<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'sub' . DIRECTORY_SEPARATOR .'header.php'?>
<style>
    .cate-type {
        color: #438EB9;
        border: 1px solid #438EB9;
        padding: 1px 3px;
    }
    .recommend {
        color: #FE9B01;
        border: 1px solid #FE9B01;
        padding: 1px 20px;
    }
</style>
<div class="ant-card page-wrap com-card static-page___2-4kT">
    <div class="ant-card-head">
        <div class="ant-card-head-wrapper">
            <div class="ant-card-head-title">网址栏目管理</div>
        </div>
    </div>
    <div class="outer-table">
        <div>
        <a href="<?=admin_url('sub/cms/category_edit')?>" class="btn-send">添加网址栏目</a>    
        </div>
        <!-- 学校表格 -->
        <table id="dynamic-table" class="table table-bordered table-hover mt10">
            <thead>
            <tr>
                <th>栏目名称</th>
                <th>栏目类型</th>
                <th>首页推荐</th>
                <th>栏目排序</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
                <?php foreach($categoryList as $category): ?>
                    <tr>
                        <td><?=$category['parent_id'] ? '&nbsp;∟ ' : ''?><?=$category['category_name']?></td>
						<td>
							<div style="display: flex;justify-content: center;align-items:center;">								
								<div style="color:#438EB9;font-size:14px;line-height:23px;width:63px;height:23px;background-image:url(<?= $staticAdminUrl ?>sub/assets/img/cms/frame_blue.png);background-size: 100% 100%;">
									<?=$category['category_type'] == CMS_CATEGORY_NORMAL ? '&nbsp;普通栏目' : '&nbsp;文章栏目' ?>
								</div>
							</div>
						</td>
						<td>
							<div style="display: flex;justify-content: center;align-items:center;">
								<?=$category['category_recommend'] ? '<div style="color:#FE9B01;font-size:14px;line-height:23px;width:63px;height:23px;background-image:url(' . $staticAdminUrl . 'sub/assets/img/cms/frame_yellow.png);background-size: 100% 100%;">推荐</div>' : ''?>
							</div>
						</td>
                        <td><?=$category['category_sort']?></td>
                        <td><?=$category['createtime']?></td>
                        <td>
                			<!-- <a class="a-edit mr20 show-category-dialog" href="#modal-category" data-toggle="modal" data-id="<?=$category['id']?>" data-title="<?=$category['category_name']?>" 
								data-sort="<?=$category['category_sort']?>" data-type="<?=$category['category_type']?>">
								修改
							</a> -->
							<a href="<?=admin_url('sub/cms/category_edit')?>/<?=$category['id']?>" class="a-edit mr20">修改</a>
                            <a class="a-delete" href="#modal-delete" data-toggle="modal" class="ml20 text-danger delete-category" data-id="<?=$category['id']?>">删除</a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>   
<!-- 栏目弹窗 -->
<div id="modal-category" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white"><img src="<?=$staticAdminUrl?>sub/assets/img/cms/no.png" style="height:18px;width:18px;"></span>
					</button>
					栏目管理
				</div>
			</div>
			<div class="modal-body no-padding">
				<div class="row">
					<div class="col-xs-12">
						<form class="form-horizontal mt10" id="category-form">
							<input type="hidden" name="id" />
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">栏目名称</label>
								<div class="col-sm-8">
									<input class="form-control" type="text" name="category_name" placeholder="请填写栏目名称"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">栏目排序</label>
								<div class="col-sm-8">
									<input class="form-control" type="number" name="category_sort" placeholder="选填。请填写栏目排序，根据序号从高往低排"/>
								</div>
                            </div>
                            <div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">上级栏目</label>
								<div class="col-sm-8">
                                    <select class="form-control" name="parent_id">
                                        <option value="0">顶级栏目</option>
                                        <?php foreach($categoryList as $category): ?>
                                            <option value="<?=$category['id']?>"><?=$category['category_name']?></option>
                                        <?php endforeach; ?>
                                    </select>
								</div>
                            </div>
                            <div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">栏目推荐</label>
								<div class="col-sm-8">
                                    <select class="form-control" name="category_recommend">
                                        <option value="0">否</option>
                                        <option value="1">推荐</option>
                                    </select>
								</div>
                            </div>
                            <div class="form-group">
								<label class="col-sm-3 control-label no-padding-right">栏目类型</label>
								<div class="col-sm-8">
                                    <select class="form-control" name="category_type">
                                        <option value="<?=CMS_CATEGORY_NORMAL?>">普通栏目</option>
                                        <option value="<?=CMS_CATEGORY_ARTICLE?>">文章类型</option>
                                    </select>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="modal-footer no-margin-top">
				<a href="javascript:;" class="" id="save-category">保存</a>
			</div>
		</div>
	</div>
</div>
<!-- 删除弹窗 -->
<div id="modal-delete" class="modal fade">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header no-padding">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white"><img src="<?=$staticAdminUrl?>sub/assets/img/cms/no.png" style="height:18px;width:18px;"></span>
					</button>
					信息
				</div>
			</div>
			<div class="modal-body no-padding">
				<input type="hidden" name="delete_id" />
				<div class="row">
					<div class="col-xs-12">
						<div class="outer-tip">
							<div>
								<img src="<?=$staticAdminUrl?>sub/assets/img/cms/warn.png" alt="">
							</div>
							<div class="tip col-xs-12">该操作将会删除栏目和所有下级栏目，是否继续？</div>
						</div>
						
					</div>
				</div>
			</div>
			<div class="modal-footer no-margin-top">
				<a href="javascript:;" class="cancel" data-dismiss="modal" aria-hidden="true">取消</a>
				<a href="javascript:;" class="delete-category">确定</a>
			</div>
		</div>
	</div>
</div>
<?php require VIEWPATH . ADMIN_DIR . DIRECTORY_SEPARATOR . 'sub' . DIRECTORY_SEPARATOR .'footer.php'?>
<script>
    $(function() {
        var categoryForm = $("#category-form");
		// 图标提示
		$(function(){
			$('[data-rel=tooltip]').tooltip();
		})
        // 显示修改弹窗
		$("body").on("click", ".show-category-dialog", function(){
			categoryForm.find("[name=id]").val($(this).data("id"));
			categoryForm.find("[name=category_name]").val($(this).data("title"));
			categoryForm.find("[name=category_sort]").val($(this).data("sort"));
			categoryForm.find("[name=category_link]").val($(this).data("link"));
			categoryForm.find("[name=category_image]").val($(this).data("image"));
		})
		// 显示删除弹窗
		$("body").on("click", ".a-delete", function(){
			var id = $(this).data("id");
			$("[name=delete_id]").val(id);
		})
		// 删除栏目
		$("body").on("click", ".delete-category", function(e){
			var id = $("[name=delete_id]").val();
			// 提交数据
			var postUrl = "<?=admin_url('cms/delete_category_action')?>";
			var postData = {"id": id};
			ajax_post(postUrl, postData, function(res){
				window.location.reload();
			})
		})
		// 提交表单
		$("#save-category").click(function(){
			categoryForm.submit();
		})
		var submitImgUrl = "<?=admin_url('cms/save_category_action')?>";
		form_submit(categoryForm, submitImgUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.reload();
				}
			});
		})
    })
</script>